<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>教育考试系统 - 教师注册</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">

  <!-- 配置Tailwind自定义主题 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#165DFF',
            secondary: '#36D399',
            accent: '#FF9F43',
            neutral: '#F8FAFC',
            'neutral-dark': '#334155',
          },
          fontFamily: {
            inter: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>

  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .card-shadow {
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
      }
      .btn-primary {
        @apply bg-primary text-white px-4 py-2 rounded-lg transition-all duration-300 hover:bg-primary/90 active:bg-primary/80;
      }
      .btn-secondary {
        @apply bg-white border border-gray-200 text-neutral-dark px-4 py-2 rounded-lg transition-all duration-300 hover:bg-gray-50 active:bg-gray-100;
      }
      .input-field {
        @apply w-full px-4 py-2.5 rounded-lg border border-gray-200 focus:border-primary focus:ring-1 focus:ring-primary transition-all outline-none;
      }
      .form-hint {
        @apply text-xs text-gray-500 mt-1;
      }
    }
  </style>
</head>
<body class="font-inter bg-gray-50 text-neutral-dark min-h-screen flex items-center justify-center p-4">
  <div class="w-full max-w-5xl grid grid-cols-1 lg:grid-cols-2 gap-8">
    <!-- 左侧品牌展示区 -->
    <div class="hidden lg:flex flex-col justify-center bg-primary rounded-2xl p-8 text-white">
      <div class="flex items-center space-x-2 mb-8">
        <i class="fa fa-graduation-cap text-3xl"></i>
        <h1 class="text-2xl font-bold">智慧教育考试系统</h1>
      </div>

      <h2 class="text-[clamp(1.5rem,3vw,2.5rem)] font-bold mb-4">教师专属<br>高效教学管理平台</h2>

      <p class="text-white/80 mb-8">
        轻松创建和管理考试，获取详细的学生成绩分析，提升教学效率和质量
      </p>

      <div class="space-y-6 mt-8">
        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-file-text-o"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">智能组卷</h3>
            <p class="text-white/70 text-sm mt-1">快速创建多样化的试卷和练习</p>
          </div>
        </div>

        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-bar-chart"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">成绩分析</h3>
            <p class="text-white/70 text-sm mt-1">多维度分析学生学习情况</p>
          </div>
        </div>

        <div class="flex items-start space-x-4">
          <div class="w-10 h-10 rounded-full bg-white/20 flex items-center justify-center flex-shrink-0 mt-1">
            <i class="fa fa-users"></i>
          </div>
          <div>
            <h3 class="font-medium text-lg">班级管理</h3>
            <p class="text-white/70 text-sm mt-1">便捷管理学生和班级信息</p>
          </div>
        </div>
      </div>
    </div>

    <!-- 右侧注册表单区 -->
    <div class="bg-white rounded-2xl p-6 md:p-8 card-shadow">
      <div class="lg:hidden flex items-center space-x-2 mb-6">
        <i class="fa fa-graduation-cap text-primary text-2xl"></i>
        <h1 class="text-xl font-bold text-primary">智慧教育考试系统</h1>
      </div>

      <h2 class="text-[clamp(1.5rem,3vw,2rem)] font-bold mb-2">教师注册</h2>
      <p class="text-gray-500 mb-6">填写以下信息完成注册</p>

      <!-- 注册表单 -->
      <form>
        <div class="mb-4">
          <label for="fullname" class="block text-sm font-medium text-gray-700 mb-1">姓名</label>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-user"></i>
            </span>
            <input type="text" id="fullname" class="input-field pl-10" placeholder="请输入您的姓名" required>
          </div>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
          <div>
            <label for="age" class="block text-sm font-medium text-gray-700 mb-1">年龄</label>
            <div class="relative">
              <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
                <i class="fa fa-calendar"></i>
              </span>
              <input type="number" id="age" class="input-field pl-10" placeholder="请输入年龄" min="18" max="65" required>
            </div>
          </div>

          <div>
            <label class="block text-sm font-medium text-gray-700 mb-1">性别</label>
            <div class="flex space-x-4">
              <label class="inline-flex items-center">
                <input id="genderMale" type="radio" name="gender" value="male" class="w-4 h-4 accent-primary" checked>
                <span class="ml-2 text-gray-700">男</span>
              </label>
              <label class="inline-flex items-center">
                <input id="genderFemale" type="radio" name="gender" value="female" class="w-4 h-4 accent-primary">
                <span class="ml-2 text-gray-700">女</span>
              </label>
            </div>
          </div>
        </div>

        <div class="mb-4">
          <label for="position" class="block text-sm font-medium text-gray-700 mb-1">职位</label>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-briefcase"></i>
            </span>
            <input type="text" id="position" class="input-field pl-10" placeholder="如：讲师、教授" required>
          </div>
        </div>

        <div class="mb-4">
          <label for="password" class="block text-sm font-medium text-gray-700 mb-1">设置密码</label>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-lock"></i>
            </span>
            <input type="password" id="password" class="input-field pl-10" placeholder="设置登录密码" required>
            <button type="button" class="absolute inset-y-0 right-0 flex items-center pr-4 text-gray-500 hover:text-primary" id="passwordToggle">
              <i class="fa fa-eye-slash"></i>
            </button>
            <p class="form-hint">密码长度至少8位，包含字母和数字</p>
          </div>
        </div>

        <div class="mb-6">
          <label for="confirmPassword" class="block text-sm font-medium text-gray-700 mb-1">确认密码</label>
          <div class="relative">
            <span class="absolute inset-y-0 left-0 flex items-center pl-4 text-gray-500">
              <i class="fa fa-lock"></i>
            </span>
            <input type="password" id="confirmPassword" class="input-field pl-10" placeholder="再次输入密码" required>
          </div>
        </div>

        <div class="mb-6">
          <label class="flex items-start">
            <input type="checkbox" class="w-4 h-4 accent-primary mt-1" required>
            <span class="ml-2 text-sm text-gray-600">
              我已阅读并同意<a href="#" class="text-primary hover:underline">《用户服务协议》</a>和<a href="#" class="text-primary hover:underline">《隐私政策》</a>
            </span>
          </label>
        </div>

        <button id="register" type="button" class="btn-primary w-full py-3 text-base font-medium mb-4">
          完成注册
        </button>

        <div class="text-center text-sm text-gray-500">
          <span>已有账号? </span>
          <a href="/" class="text-primary hover:underline">立即登录</a>
        </div>
      </form>
    </div>
  </div>

  <footer class="fixed bottom-4 left-0 right-0 text-center text-gray-500 text-sm">
    <p>© 2025 智慧教育考试系统 版权所有</p>
  </footer>

  <script>
    // 密码显示/隐藏功能
    const setupPasswordToggle = () => {
      const toggleBtn = document.getElementById('passwordToggle');
      const passwordInput = document.getElementById('password');

      toggleBtn.addEventListener('click', () => {
        const type = passwordInput.getAttribute('type') === 'password' ? 'text' : 'password';
        passwordInput.setAttribute('type', type);

        // 切换图标
        const icon = toggleBtn.querySelector('i');
        if (type === 'password') {
          icon.classList.remove('fa-eye');
          icon.classList.add('fa-eye-slash');
        } else {
          icon.classList.remove('fa-eye-slash');
          icon.classList.add('fa-eye');
        }
      });
    };

    function getSelectedGender() {
    // 分别获取每个单选按钮的选中状态
    const maleRadio = document.getElementById('genderMale');
    const femaleRadio = document.getElementById('genderFemale');

    if (maleRadio.checked) {
        return '男';
    } else if (femaleRadio.checked) {
        return '女';
    } else {
        console.log('没有选择性别');
        return null;
    }
  }

    // 密码匹配验证
    const setupPasswordValidation = () => {
      const passwordInput = document.getElementById('password');
      const confirmInput = document.getElementById('confirmPassword');

      const validate = () => {
        if (passwordInput.value && confirmInput.value) {
          if (passwordInput.value !== confirmInput.value) {
            confirmInput.setCustomValidity('两次输入的密码不一致');
            confirmInput.classList.add('border-red-500');
            confirmInput.classList.remove('focus:border-primary', 'focus:ring-primary');
          } else {
            confirmInput.setCustomValidity('');
            confirmInput.classList.remove('border-red-500');
            confirmInput.classList.add('focus:border-primary', 'focus:ring-primary');
          }
        }
      };

      passwordInput.addEventListener('input', validate);
      confirmInput.addEventListener('input', validate);
    };

    const but = document.getElementById('register')
    but.addEventListener('click',async () => {
      dataform = new FormData()
      dataform.append('name', document.getElementById('fullname').value)
      dataform.append('age', document.getElementById('age').value)
      dataform.append('gender', getSelectedGender())
      dataform.append('job', document.getElementById('position').value)
      dataform.append('password', document.getElementById('password').value)
      const response = await fetch('/register',{
        method:'POST',
        body:dataform
      })
      result = await response.json()
      if (result.success){
        alert(`注册成功，账号：${result.username}`)
        window.location.href = result.redirect || '/'
      }
      else {
        alert(`注册失败，${result.error}`)
      }
    })


    // 页面加载完成后初始化
    document.addEventListener('DOMContentLoaded', () => {
      setupPasswordToggle();
      setupPasswordValidation();
    });
  </script>
</body>
</html>